package com.clubs.coding.Service.Impl;

import com.clubs.coding.Service.AthLeaveService;

import com.clubs.coding.model.dao.AthLeaveMapper;
import com.clubs.coding.model.dao.LearningMapper;
import com.clubs.coding.model.pojo.AthLeave;

import com.clubs.coding.model.pojo.MakeTime;
import com.clubs.coding.model.request.AthLeaveReq;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AthLeaveServiceImpl implements AthLeaveService {
    @Autowired
    AthLeaveMapper athLeaveMapper;
    @Autowired
    LearningMapper learningMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
    //请假
public void goleave(AthLeaveReq athLeaveReq){
        learningMapper.deleteByopenidAndMakeId(athLeaveReq.getOpenid(), athLeaveReq.getApplicationId());
        AthLeave athLeave = new AthLeave();

        BeanUtils.copyProperties(athLeaveReq,athLeave);
        athLeaveMapper.insertSelective(athLeave);

    }
    //个人的旷课和请假
    @Override
    public PageInfo truant(String mobile, Integer leave, Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<MakeTime> makeTimes = athLeaveMapper.selectByMobileMakeTimes(mobile, leave);
        PageInfo pageInfo = new PageInfo(makeTimes);
        pageInfo.setList(makeTimes);
        return pageInfo;
    }

}
